#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
motifs_xcel_class_01 (motifs 09)
23 de septiembre de 2008
"""
#
import xlwt
from motifs_common_01 import AMINOACIDS
#
#
class XcelMotif(xlwt.Workbook):
    def __init__(self):
        xlwt.Workbook.__init__(self)
        
    def sheet_motifs(self, name, diccio):
        "hoja de motivos"
        ws = self.add_sheet(name)
        row = 0
        for item in diccio:
            for motif in diccio[item]:
                ws.write(row, 0, item.strip())  #strip?
                ws.write(row, 1, motif)
                row += 1
    
    def sheet_frecs(self, name, frecs, head):
        "hoja de frecuencias"
        style = xlwt.XFStyle()
        style.num_format_str = "0"
        ws = self.add_sheet(name)
        title = " | ".join(head)    
        ws.write(0, 0, title)
        ws.write(1, 0, "pos")
        for number in range(len(frecs[0])):
            ws.write(1, number+1, number+1)
        for idx, aa in enumerate(AMINOACIDS):
            for pos, frec in enumerate(frecs[idx]):    
                ws.write(idx+2, 0, aa)
                ws.write(idx+2, pos+1, frec, style)

    def sheet_graph(self, name, graph, head):
        "hoja con grafico xmotif"
        ws = self.add_sheet(name)
        title = " | ".join(head)
        ws.write(0, 0, title)
        ws.insert_bitmap(graph, 1, 0)

    def xsave(self, arch):
        archout = arch + "out.xls"
        self.save(archout)
        
if __name__ == "__main__":
    pass
    